import tensorflow as tf
from utils.create_log import get_log


@tf.function
def strjoin(x, y):
    return tf.strings.join([x, y], separator=' ')


def run():
    # 创建日志
    log_path = '../data/logs/tensorboard_autograph'
    logdir = get_log(log_path=log_path)

    writer = tf.summary.create_file_writer(logdir)
    # 开启跟踪
    tf.summary.trace_on(graph=True, profiler=True)
    # 执行autograph
    rs = strjoin(x='hello', y='world')
    tf.print(rs)

    # 将计算图信息写入log
    with writer.as_default():
        tf.summary.trace_export(name='autograph', step=0, profiler_outdir=logdir)


if __name__ == '__main__':
    run()
